package com.bootssm.service.impl;

import com.bootssm.dao.NotesMapper;
import com.bootssm.entity.Notes;
import com.bootssm.entity.NotesVO;
import com.bootssm.service.NotesService;
import com.bootssm.utils.IdWorker;
import com.bootssm.utils.TimeUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.Date;
import java.util.List;

@Service
public class NotesServiceImpl implements NotesService {
    @Autowired
    NotesMapper notesMapper;

    @Autowired
    IdWorker idWorker;

    @Override
    public List<Notes> findAll(NotesVO notesVO) {
        return notesMapper.findAll(notesVO);
    }

    @Override
    public Integer getCount(NotesVO notesVO) {
        return notesMapper.getCount(notesVO);
    }

    @Override
    public void insert(Notes notes) {
        notes.setNoteid(idWorker.nextId() + "");
       // LocalDateTime currentTime = LocalDateTime.now();
        notes.setCreatetime(TimeUtil.getCurrentTime(new Date()));
        notesMapper.insert(notes);
    }

    @Override
    public void deleteById(String noteid) {
        notesMapper.deleteById(noteid);
    }

    @Override
    public void update(Notes notes) {
        LocalDateTime currentTime = LocalDateTime.now();

        notes.setUpdatetime(TimeUtil.getCurrentTime(new Date()));
        notesMapper.update(notes);
    }

    @Override
    public Notes findById(String noteid) {
        return notesMapper.findById(noteid);
    }
}
